package io.gitee.caoxiaoyu97.service.split.agent;

import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.util.ClassUtils;

import java.beans.Introspector;

/*********************************************************
 * 文件名称：ServiceSplitSBeanNameGenerator.java
 * 系统名称：cxycloud
 * 模块名称：io.gitee.caoxiaoyu97.service.split
 * 功能说明：bean名称生成器
 * 开发人员 @author：caoxy
 * 开发时间 @date：2023/8/4 14:53
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class ServiceSplitSBeanNameGenerator extends AnnotationBeanNameGenerator {
    private static final String BEAN_NAME_SUFFIX = "ServiceSplitProxy";

    @Override
    public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
        StringBuilder stringBuilder = new StringBuilder();
        PropertyValues propertyValues = definition.getPropertyValues();
        String interfaceName = (String)propertyValues.getPropertyValue("proxyInterfaces").getValue();
        String shortClassName = ClassUtils.getShortName(interfaceName);
        return stringBuilder.append(Introspector.decapitalize(shortClassName)).append(BEAN_NAME_SUFFIX).toString();
    }
}